package com.zmykj.hik.hikService.Controllers;


import com.zmykj.hik.hikService.Common.CommonClass;
import com.zmykj.hik.hikService.Common.CommonMethod;
import com.zmykj.hik.hikService.Service.Alarm.EAlarm;
import com.zmykj.hik.hikService.Service.CMS.ECMS;
import com.zmykj.hik.hikService.Service.CMS.OnlineDevManager;
import com.zmykj.hik.hikService.Service.Storage.ESS;
import com.zmykj.hik.hikService.Service.Stream.EStream;

public class GlobalController {

    private static boolean m_bIsInit = false;
    public static ECMS m_serverECMS = null;
    public static EAlarm m_serverEAlarm = null;
    public static ESS m_serverESS = null;
    public static EStream m_serverEStream = null;

    public static ECMS GetCMS(){return m_serverECMS;}

    public static EAlarm GetAlarm(){return m_serverEAlarm;}

    public static ESS GetSS(){return m_serverESS;}

    public static EStream GetStream(){return m_serverEStream;}

    public static boolean GetInitStatus()
    {
        return m_bIsInit;
    }

    public static void SetInitStatus(boolean bInitStatus)
    {
        m_bIsInit = bInitStatus;
    }

    public static void GlobalUnload()
    {
        if(OnlineDevManager.g_Devs.size() != 0)
        {
            OnlineDevManager.g_Devs.clear();
            OnlineDevManager.g_Devs = null;
            System.out.println("Device list clear\n");
        }

        if(CommonMethod.GetListenInfo() != null)
        {
            CommonClass.g_struListenInfo = null;
        }

        if(CommonMethod.GetServerInfo() != null)
        {
            CommonClass.g_struServerInfoV50 = null;
        }

        if(m_serverECMS.IsRunning())
        {
            m_serverECMS.StopEcms();
            m_serverECMS = null;
            System.out.println("CMS logout\n");
        }
        if(m_serverEAlarm.IsRunning())
        {
            m_serverEAlarm.StopElarm();
            m_serverEAlarm = null;
            System.out.println("Alarm logout\n");
        }
        if(m_serverESS.IsRunning())
        {
            m_serverESS.StopESS();
            m_serverESS = null;
            System.out.println("ESS logout\n");
        }
        if(m_serverEStream.IsRunning())
        {
            m_serverEStream.StopEStream();
            m_serverEStream = null;
            System.out.println("EStream logout\n");
        }

        SetInitStatus(false);
    }

    public static void InitLocalConfig(){
        CommonClass.g_struListenInfo = new CommonClass.ListenInfo();
        CommonClass.g_struServerInfoV50 = new CommonClass.NET_EHOME_SERVER_INFO_V50();
    }
}
